package com.kangkang.shixi;


import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Shiyou02_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<String> sb = new ArrayList<>();
        while (true) {
            String input = scanner.nextLine();
            if ("".equals(input))
                break;
            sb.add(input);
        }
        List<Student> studentList = sb.stream().map(new Function<String, Student>() {
            @Override
            public Student apply(String s) {
                String[] strings = s.split("\t");
                Student student = new Student(Integer.parseInt(strings[0]),
                        strings[1],
                        strings[0].charAt(5) % 2 == 1 ? '男' : '女',
                        strings[3]);
                student.addScore(Integer.parseInt(strings[4]));
                student.addScore(Integer.parseInt(strings[5]));
                student.addScore(Integer.parseInt(strings[6]));
                student.addScore(Integer.parseInt(strings[7]));
                return student;
            }
        }).collect(Collectors.toList());
        Collections.sort(studentList);
        studentList.forEach(student -> System.out.println(student.toString()));
        //按班级分组
        List<StudentClass> scList = new ArrayList<>();
        studentList.forEach(student -> {
            //是否有班
            if (scList.size() == 0) {
                scList.add(new StudentClass(student.getClsName()));
            }
            boolean clsExistence = false;
            for (StudentClass studentClass : scList) {
                if (Objects.equals(studentClass.getName(), student.getClsName())) {
                    studentClass.addStudent(student);
                    clsExistence = true;
                }
            }
            if (!clsExistence) {
                scList.add(new StudentClass(student.getClsName()));
            }
        });
        for (StudentClass studentClass : scList) {
            studentClass.computeAvgScores();
        }
        Collections.sort(scList, new Comparator<StudentClass>() {
            @Override
            public int compare(StudentClass p1, StudentClass p2) {
                return p1.getAvgScores() - p2.getAvgScores() > 0 ? 1 : -1;
            }
        });
        for (StudentClass studentClass : scList) {
            System.out.println(studentClass);
        }
    }

}
